import React from 'react';
import {connect, history} from 'umi';
import Product from "@/pages/home/components/Product";
import Archives from "@/pages/home/components/Archives";
import Category from "@/pages/home/components/Category";
import Admin from "@/pages/sys/monitor";

const Index = (props) => {
  const {match: {params: {slugCategory, page}, url : pageUrl, }, route,} = props;

  const {category, module} = route && route['/'] || {};

  const state = {slugTerm: category?? slugCategory, url: '/', pageUrl, page};
  const moduleMap = {
    'product': <Product {...state} />,
    'category': <Category {...state} />,
    'archives': <Archives {...state} count={8} pageName="product" />,
    'admin': <Admin />,
  };

  if (module === 'admin') {
    history.push('/admin/sys');
    return (<></>);
  }

  const body = module && moduleMap[module];

  return (<>{body || ''}</>);
};

export default connect(({ user, loading }) => ({
  route: user.route,
  loading: loading.effects['user/fetchCurrent'],
}))(Index);